package com.lc.hongtai.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.lc.hongtai.MyApplication;
import com.lc.hongtai.R;
import com.lc.hongtai.adapter.FragmentAdapter2;
import com.zcx.helper.activity.AppV4Fragment;
import com.zcx.helper.bound.BoundViewHelper;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;

import static com.lc.hongtai.R.id.vp;


/**
 * 动态
 * 
 * @author Ansen
 * @create time 2015-09-08
 */
public class DynamicFragment2 extends AppV4Fragment implements View.OnClickListener, OnTabSelectListener {
	private ViewPager vp_FindFragment_pager;
	private FragmentPagerAdapter fAdapter;
	private List<Fragment> list_fragment;
	private List<String> list_title;
	private Fragment1 fragment1;
	private Fragment2 fragment2;
	SlidingTabLayout tl_2;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = BoundViewHelper.boundView(this, MyApplication.scaleScreenHelper.loadView((ViewGroup) inflater.inflate(R.layout.fragment_second, null)));
		ButterKnife.bind(this, view);

		vp_FindFragment_pager= (ViewPager) view.findViewById(vp);
		tl_2= (SlidingTabLayout) view.findViewById(R.id.tl_2);

		initControls();


		return view;
	}



	private void initControls() {

		fragment1 = new Fragment1();
		fragment2 = new Fragment2();


		list_fragment = new ArrayList<>();

		list_fragment.add(fragment1);
		list_fragment.add(fragment2);


		list_title = new ArrayList<>();
		list_title.add("fragment1");
		list_title.add("fragment2");


		fAdapter = new FragmentAdapter2(getActivity().getSupportFragmentManager(), list_fragment, list_title);

		vp_FindFragment_pager.setAdapter(fAdapter);

		tl_2.setViewPager(vp_FindFragment_pager);
		tl_2.setOnTabSelectListener(this);

	}


	@Override
	public void onTabSelect(int position) {
		Toast.makeText(getActivity(), "onTabSelect&position--->" + position, Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onTabReselect(int position) {
		Toast.makeText(getActivity(), "onTabReselect&position--->" + position, Toast.LENGTH_SHORT).show();
	}




	@Override
	public void onDestroyView() {
		super.onDestroyView();
		ButterKnife.unbind(this);
	}


	@Override
	public void onClick(View v) {

	}
}
